/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package neuronalenetzeelearning.view.controlpanel;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import neuronalenetzeelearning.model.Graph;
import neuronalenetzeelearning.view.help.HelpPanel;
import neuronalenetzeelearning.view.help.HelpWindowFactory;

/**
 *
 * @author Henning Ainödhofer
 * Aktivierungsfunktion
 *  -   Linear
 *  -   Schwellenwert
 * Ausgabefunktion
 *  -   Linear
 *  -   Sigmoid
 * 
 */
public class StepFunktionPanel extends GraphPanelProperty {
    JComboBox stepFunktionChooser;
    JComboBox outputFunktion;
    JSpinner learningRateSpinner;

    public StepFunktionPanel(){
        super();
        this.setBackground(background);
        this.setLayout(grid);

        this.setBorder(javax.swing.BorderFactory.createTitledBorder("Bitte wählen Sie die Aktivierungsfunktion und die Lernrate aus!"));

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 1;

        JLabel bord = new JLabel("------------------------------------------------------------------------------------------------------------------");
        add(bord, constraints);

        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.gridx = 1;
        constraints.gridy = 2;

        JLabel stepFunktionChooserLabel = new JLabel("Aktivierungsfunktion");

        add(stepFunktionChooserLabel, constraints);

        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.insets = new Insets(10, 10, 10, 10);
        constraints.gridx = 2;
        constraints.gridy = 2;

        stepFunktionChooser = new JComboBox();
        stepFunktionChooser.setModel(new DefaultComboBoxModel(new String[] { "Linear", "Schwellenwert", "Sigmoid"  }));
        add(stepFunktionChooser, constraints);

        constraints.gridx = 1;
        constraints.gridy = 3;

        JLabel outputFunktionLabel = new JLabel("Ausgabefunktion");

        add(outputFunktionLabel, constraints);

        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 2;
        constraints.gridy = 3;

        outputFunktion = new JComboBox();
        outputFunktion.setModel(new DefaultComboBoxModel(new String[] { "Linear"}));
        add(outputFunktion, constraints);

        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.gridy = 4;

        JLabel learningRateLabel = new JLabel("Lernrate");
        add(learningRateLabel, constraints);

        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.gridheight = 1;
        constraints.gridx = 2;
        constraints.gridy = 4;

        learningRateSpinner = new JSpinner();
        learningRateSpinner.setModel(new javax.swing.SpinnerNumberModel(0.5, 0.1, 1, 0.1));
        learningRateSpinner.setBackground(background);
        this.add(learningRateSpinner, constraints);

        constraints.gridx = 1;
        constraints.gridy = 5;

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.fill = GridBagConstraints.HORIZONTAL;

        navigation.add(previous, constraints);
        navigation.add(getHelpButton(), constraints);
        navigation.add(next, constraints);

        add(navigation, constraints);

        setVisible(true);
    }

    public int getstepFunktion(){
        return this.stepFunktionChooser.getSelectedIndex();
    }

    public int getoutputFunktion(){
        return this.outputFunktion.getSelectedIndex();
    }
    public double getlearningRateSpinnerValue(){
        return Double.parseDouble(this.learningRateSpinner.getModel().getValue().toString());
    }
    @Override
    public void setGraph(Graph graph){
        this.graph = graph;
    }
    
    @Override
    public void writePropertysToFile(String prop){
        super.propertys.add(prop);
    }
    @Override
    public LinkedList<String>getPropertys(){
        return super.propertys;
    }

    public static void main(String[] args) {
        JFrame test = new JFrame();
        Dimension size = new Dimension();
        size.setSize(800, 800);
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.setPreferredSize(size);

        Graph graph = new Graph();
        test.add(new StepFunktionPanel());

        test.setResizable(false);
        test.pack();
        test.setVisible(true);
    }

//            @Override
//    public ActionListener getActionListener() {
//        return new ActionListener() {
//
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("Help from Learning Rule Chooser Panel");
//            }
//        };
//
//    }

            @Override
    public ActionListener getActionListener() {
        return new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                HelpWindowFactory.createHelpWindow(new HelpPanel("src/neuronalenetzeelearning/view/help/resources/linear-Sigmoid-Schwe.png"));
            }
        };

    }
}
